package ${packageName};

import java.util.concurrent.locks.ReentrantLock;

/**
 * 数据存储
 */
public class ${className} {

	public static void lock(Object obj,ReentrantLock[] locks){
		ReentrantLock lock = getLock(obj,locks);
		lock.lock();
	}
	
	public static void unlock(Object obj,ReentrantLock[] locks){
		ReentrantLock lock = getLock(obj,locks);
		lock.unlock();
	}
	
	private static ReentrantLock getLock(Object k,ReentrantLock[] locks) {
		int h = 0;
		h ^= k.hashCode();
		h += (h << 15) ^ 0xffffcd7d;
		h ^= (h >>> 10);
		h += (h << 3);
		h ^= (h >>> 6);
		h += (h << 2) + (h << 14);
		int index = (locks.length - 1) & (h ^ (h >>> 16));
		return locks[index];
	}
	
	<#list tables as table>
	// ${table.tableName}
	public static final ReentrantLock[] ${table.x_tableName}_locks = new ReentrantLock[16];
	</#list>
	
	
	static{
		<#list tables as table>
		// ${table.tableName}
		for (int i = 0; i < ${table.x_tableName}_locks.length; i++)${table.x_tableName}_locks[i] = new ReentrantLock();
		</#list>
	}
}